<%-- 
    Document   : index
    Created on : 11/11/2008, 10:25:07
    Author     : tiago
--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,br.com.radaction.DAO.UsuarioDAO,br.com.radaction.DTO.Usuario" %>
<%@ include file="conexao.jsp" %>
<%

        if ("login".equals(request.getParameter("acao"))) {
            String login = request.getParameter("txtUsuario");
            String senha = request.getParameter("txtSenha");
            UsuarioDAO usrDao = new UsuarioDAO(conn);
            Usuario usuario = usrDao.retrieve(login);
            if (usuario == null || !usuario.validaSenha(senha)) {
                request.setAttribute("mensagem", String.format("Usuário ou Senha Inválidos.[%s]", login));
                RequestDispatcher dispatcher = request.getRequestDispatcher("erro.jsp");
                dispatcher.forward(request, response);
                if (conn != null) {
                    conn.close();
                }
                return;
            } else {
                session.setAttribute("UsuarioLogado", Boolean.TRUE);
            }
        }
        Boolean usuarioLogado = (Boolean) session.getAttribute("UsuarioLogado");
        if (usuarioLogado != null && usuarioLogado.booleanValue()) {
%>

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>RADAcademics Interface Web</title>
        <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/>
    </head>

    <body>

        <div class="wrapper">

            <div class="container">

                <div class="main">

                    <div class="content">

                        <div class="title"><img src="images/logorad2.png" width="150"></div>

                        <h2>BEM VINDO </h2>
                        <div class="descr"><%= new java.util.Date()%></div>

                        <blockquote><p style="font-size: 20pt;text-align:justify">Para cadastrar ou visualizar os dados dos cursos, disciplinas e avaliaçãos use o menu ao lado direito da pagina.</p></blockquote>

                        <p></p>



                    </div>

                    <div class="sidenav">

                        <h2>Login</h2>
                        <ul>
                            <form action="sair.jsp">
                                <li><input type="submit" value="Sair" name="Sair" /></li>
                            </form>

                        </ul>

                        <h2>Menu</h2>
                        <ul>
                            <li><a href="cursos.jsp">Cursos</a></li>
                            <li><a href="disciplinas.jsp">Disciplinas</a></li>
                            <li><a href="avaliacoes.jsp">Avaliações</a></li>

                        </ul>

                    </div>

                    <div class="clearer"></div>

                </div>

                <div class="footer">

                    <div class="left">&copy; 2008 <a href="http://www.radaction.com.br">radaction.com</a>. Valid <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> &amp; <a href="http://validator.w3.org/check?uri=referer">XHTML</a></div>

                    <div class="right">Design by <a href="http://arcsin.se/">R4D4C710N</a></div>

                    <div class="clearer"><span></span></div>

                </div>

            </div>

        </div>

    </body>

</html>
<%
            if (conn != null) {
                conn.close();
            }
        } else {
            if (conn != null) {
                conn.close();
            }
            request.setAttribute("mensagem", "Usuário e Senha inválidos");
            RequestDispatcher dispatcher = request.getRequestDispatcher("erro.jsp");
            dispatcher.forward(request, response);
        }
%>